<style>
    .mobile-dialog li
    {
        line-height: 40px;
        padding-left: 50px;
        font-family: "微软雅黑";
        font-size: 16px;
    }
</style>
<div id="dialogTel" title="绑定手机" style="display: none;">
    <ul class="mobile-dialog">
        <input type="hidden" id="dialogFlag" value="0">
        <li><span id="dialogTel_phone">当前手机号码：</span></li>
        <li><input type="text" name="newMobile" id="newMobile" value="" style="display: none;" placeholder="新手机号码"></li>
        <li><button type="button" id="sendVerCodeBtn" style="cursor: pointer;border: #696969 1px solid; border-radius: 3px;background: #eeeeee; height: 30px; width: 160px; color: #666666; font-weight: bold; font-size: 16px;">点此获取验证码</button></li>
        <li><input type="text" id="verCode" name="verCode" placeholder="6位数字"></li>
        <li><button type="button" id="submitDialogBtn" style="cursor: pointer;border: #ff0000 1px solid; border-radius: 3px;background: #ff0000; height: 30px;width: 160px; font-weight: bold; color: #ffffff; font-size: 16px;">确定</button></li>
        <li style="font-size: 14px; margin-top: 10px; background: #FFF9CC; line-height: 20px;"><div><span style="font-family: 微软雅黑;font-size: 16px;">没收到短信验证码？</span><br/>
                1、网络通讯异常可能会造成短信丢失，请重新获取或稍后再试。<br/>
                2、请核实手机是否已欠费停机，或者屏蔽了系统短信。<br />
                3、如果手机已丢失或停用， 请选择其他验证方式 。</div></li>
    </ul>
</div>
<script>

    $(function(){
        var countdown =10;
        var member_tel = $("#member_mobile").val();
        $("#dialogTel_phone").append(member_tel);
        $("#clickBind").on("click",function(){
            $("#dialogFlag").val(1);
            $("#verCode").val('');
            $("#dialogTel").dialog({
                height:320,
                width:500,
                title:"绑定手机号码",
                resizable:false,
                modal:true
            });
        });
        $("#changeTel").on("click",function(){
            if($("#bindStatus").val()==1)
            {
                alert("手机已绑定，请先解除绑定状态！");
            }else
            {
                $("#dialogFlag").val(2);
                $("#verCode").val('');
                $("#newMobile").show();
                $("#dialogTel").dialog({
                    height:350,
                    width:500,
                    title:"更换手机号码",
                    resizable:false,
                    modal:true
                });
            }
        });
        $("#unbind").on("click",function(){
            $("#dialogFlag").val(3);
            $("#verCode").val('');
            $("#dialogTel").dialog({
                height:320,
                width:500,
                title:"解除手机绑定",
                resizable:false,
                modal:true
            });
        });
        $("#sendVerCodeBtn").on("click",function(){
            var flag = $("#dialogFlag").val();
            $.getJSON(SITEURL+"/shop/api.php",{act:"sendSMS",op:"verCode",mobile:member_tel,flag:flag},function(data){
                if(data.result.successful == "true")
                {
                    setSendVerCodeBtn();
                }
            });
        });

        $("#submitDialogBtn").on("click",function(){
            var verCodeStr = $("#verCode").val();
            var flag = $("#dialogFlag").val();
            var newMobileStr = $("#newMobile").val();
            $.getJSON(SITEURL+"/shop/api.php",{act:'sendSMS',op:'checkCode',mobile:member_tel,verCode:verCodeStr,flag:flag},function(data){
                if(data.result==true)
                {
                    $.getJSON(SITEURL+"/shop/api.php",{act:'sendSMS',op:'checkSuccess',mobile:member_tel,newMobile:newMobileStr,flag:flag},function(e){
                        if(e.result)
                        {
                            alert(e.message);
                            $("#dialogTel").dialog("close");
                            window.location.reload();
                        }
                    });
                }
                else
                {
                    alert(data.result);
                }
            });
        });

        function setSendVerCodeBtn()
        {
            if(countdown==0)
            {
                $('#sendVerCodeBtn').css("color","#666666");
                $('#sendVerCodeBtn').html('点此获取验证码');
                $('#sendVerCodeBtn').removeAttr('disabled');
                countdown = 10;
            }
            else
            {
                $('#sendVerCodeBtn').attr('disabled',true);
                $('#sendVerCodeBtn').css("color","#aaaaaa");
                $('#sendVerCodeBtn').html('重新发送'+countdown);
                countdown--;
                setTimeout(function(){setSendVerCodeBtn()},1000);
            }
        }
    });


</script>